package com.fast.develop.api.rest.registor;

import com.fast.develop.api.rest.FileRest;
import com.fast.develop.core.enums.RequestMethod;
import com.fast.develop.core.properties.DomainRuntimeProperties;
import com.fast.develop.core.web.AbstractMappingRegistor;
import com.fast.develop.core.web.MappingInfo;
import com.fast.develop.core.web.MappingRegistor;
import com.fast.develop.integration.web.MvcMappingHandlerMapping;
import lombok.SneakyThrows;


/**
 * @author 莫寅
 * @createTime 2022-06-18 04:52
 * @desc：
 */
public class FileMappingRegistor extends AbstractMappingRegistor implements MappingRegistor {


    public static final String KEY = "/resource";


    public FileMappingRegistor(MvcMappingHandlerMapping mvcMappingHandlerMapping, DomainRuntimeProperties domainRuntimeProperties, FileRest fileRest) {
        super(mvcMappingHandlerMapping, domainRuntimeProperties, fileRest);
    }


    @Override
    @SneakyThrows
    public void registerMapping() {
        MappingInfo getResourceTree = new MappingInfo(new String[]{getPath("tree")}, new RequestMethod[]{RequestMethod.GET});
        registerMapping(getResourceTree, FileRest.class.getDeclaredMethod("getResourceTree"));

        MappingInfo createFolder = new MappingInfo(new String[]{getPath("folder")}, new RequestMethod[]{RequestMethod.POST});
        registerMapping(createFolder, FileRest.class.getDeclaredMethod("createFolder", String.class));

        MappingInfo createFile = new MappingInfo(new String[]{getPath("file")}, new RequestMethod[]{RequestMethod.POST});
        registerMapping(createFile, FileRest.class.getDeclaredMethod("createFile", String.class));

        MappingInfo rename = new MappingInfo(new String[]{getPath("rename/{name}")}, new RequestMethod[]{RequestMethod.PUT});
        registerMapping(rename, FileRest.class.getDeclaredMethod("rename", String.class, String.class));

        MappingInfo remove = new MappingInfo(new String[]{getPath("")}, new RequestMethod[]{RequestMethod.DELETE});
        registerMapping(remove, FileRest.class.getDeclaredMethod("remove", String.class));

        MappingInfo getResource = new MappingInfo(new String[]{getPath("")}, new RequestMethod[]{RequestMethod.GET});
        registerMapping(getResource, FileRest.class.getDeclaredMethod("read", String.class));
    }

    @Override
    public String type() {
        return KEY;
    }


    @Override
    protected String getKey() {
        return KEY;
    }
}
